BEGIN TRANSACTION;
BEGIN TRY
    -- 检查是否已提交
    IF NOT EXISTS (SELECT 1 FROM ExamAnswers WHERE UserID = 'stu001' AND QuestionID = 10)
    BEGIN
        -- 插入答案
        INSERT INTO ExamAnswers (UserID, QuestionID, Answer) 
        VALUES ('stu001', 10, 'A');
    END
    COMMIT TRANSACTION;
END TRY
BEGIN CATCH
    ROLLBACK TRANSACTION;
    RAISERROR('提交失败', 16, 1);
END CATCH;
